package com.atguigu.iterator;

import java.util.Iterator;

/**
 * @Description: 具体的聚合物，持有集合对象，并且提供方法返回具体的迭代器
 * @Author lixiaolong
 * @Date 2023/10/11
 */
public class ComputerCollege implements College {

    Department[] departments;// 集合对象
    int numOfDepartment = 0;// 当前数组对象个数


    public ComputerCollege() {
        departments = new Department[5];
        addDepartment("Java专业", " Java专业 ");
        addDepartment("PHP专业", " PHP专业 ");
        addDepartment("C++专业", " C++专业 ");

    }


    @Override
    public String getName() {
        return "计算机学院";
    }

    @Override
    public void addDepartment(String name, String desc) {
        Department department = new Department(name, desc);
        departments[numOfDepartment] = department;
        numOfDepartment++;
    }

    @Override
    public Iterator createIterator() {
        return new ComputerCollegeIterator(departments);
    }

}
